<template>
	<view :class="type != 1 && 'page-container'" :style="viewColor">
		<productConSwiper :imgUrls="pics"></productConSwiper>
		<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
		<view class="product-info">
			<view class="product-title"><text>{{detail.type == 1 ? '55折' : '好货'}}</text>{{detail.title || ''}}</view>
			<view class="product-price">¥<text>{{detail.attr[0].price || 0.00}}</text></view>
			
			<view class="product-in">
				<view class="product-original">市场价:¥{{detail.attr[0].original_price || 0.00}}</view>
				<view class="product-stock">库存:{{detail.attr[0].stock || 0}}</view>
			</view>
		</view>
		<view class="product-content">
			<view class="product-content-title">产品介绍</view>
			<view class="product-keywords">{{detail.keywords || ''}}</view>
			<view class="product-description">{{detail.description || ''}}</view>
		</view>
		<!-- <view class="buy-fixed"> -->
			<view  v-if="!type" class="buy-fixed-button" @click="getConfirm">立即购买</view>
		<!-- </view> -->
		<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
	</view>
</template>

<script>
	import productConSwiper from '@/components/productConSwiper';
	import {
		getUserProductDetail
	} from "@/api/user_product"
	import { mapGetters } from "vuex";
	import { configMap } from "@/utils";
	import parser from "@/components/jyf-parser/jyf-parser";
	import authorize from '@/components/Authorize';
	import { HTTP_REQUEST_URL } from '@/config/app';
	const app = getApp();
	export default {
		components: {
			"jyf-parser": parser,
			authorize,
			productConSwiper
		},
		data() {
			return {
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false, //是否隐藏授权
				id: 0,
				type: 0, // 0好货列表进入 1我的好货进入
				detail: {},
				pics: [],
			};
		},
		beforeDestroy() {
		},
		computed: {...configMap({sys_intention_agree:''},mapGetters(['isLogin','viewColor','keyColor']))
		},
		onLoad(options) {
			if (this.isLogin) {
				this.id = options.id
				this.type = options.type || 0;
				this.getDetail();
			} else {
				this.isAuto = true;
				this.isShowAuth = true
			}
		},
		onShow() {},
		onReady() {},
		methods: {
			getDetail() {
				let that = this,
				data = {
					status: 1,
					is_show: 1,
				}
				if(that.type == 1){
					data.status = '';
					data.is_show = '';
				}
				getUserProductDetail(that.id, data).then(res=>{
					that.detail = res.data;
					that.pics = res.data.pics;
					that.pics.unshift(res.data.thumb);
					that.$set(that, 'pics', that.pics);
					that.$set(that, 'detail', that.detail)
				}).catch(err=>{
					that.$util.Tips({title:err},{
						tab: 3,
					})
				})
			},
			getConfirm() {
				this.$util.Tips('/pages/extends/user_product/order_confirm?id='+this.id)
			},
			// 授权回调
			onLoadFun: function() {
				this.isShowAuth = false;
				return uni.switchTab({
					url: '/pages/user/index'
				});
			},
			// 授权关闭
			authColse: function(e) {
				this.isShowAuth = e
			}
		}
	}
</script>

<style scoped lang="scss">
	.page-container {
		padding-bottom: 110rpx;
	}
	.product-info {
		padding: 0 26rpx 40rpx;
		background-color: #fff;
		.product-price {
			padding-top: 20rpx;
			font-size: 47rpx;
			font-weight: 500;
			color: #F50402;
			line-height: 59rpx;
			text {
				font-size: 38rpx;
				font-weight: 400;
			}
		}
		.product-title {
			padding-top: 40rpx;
			font-size: 36rpx;
			font-weight: bold;
			color: #2C332D;
			line-height: 54rpx;
			text {
				padding: 8rpx 20rpx;
				background: linear-gradient(135deg, #898989 0%, #262424 100%);
				border-radius: 10rpx;
				font-size: 24rpx;
				font-weight: 400;
				color: #FEE809;
				line-height: 34rpx;
				margin-right: 20rpx;
			}
		}
		.product-in {
			font-size: 26rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #999B97;
			line-height: 36rpx;
			margin-top: 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
	}
	.product-content {
		margin-top: 20rpx;
		padding: 40rpx 26rpx;
		font-size: 30rpx;
		font-weight: 400;
		color: #2C332D;
		background-color: #fff;
		.product-content-title{
			font-size: 36rpx;
			font-weight: 500;
			color: #2C2C2C;
			line-height: 50rpx;
			margin-bottom: 30rpx;
		}
	}
	.buy-fixed-button {
		width: 604rpx;
		height: 100rpx;
		background: #FFE103;
		border-radius: 50rpx;
		position: fixed;
		left: 74rpx;
		bottom: 62rpx;
		font-size: 34rpx;
		font-weight: 500;
		color: #1C211D;
		line-height: 48rpx;
		padding: 26rpx 0;
		text-align: center;
	}
	/* .buy-fixed {
		padding: 0 30rpx;
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		box-sizing: border-box;
		height: 100rpx;
	height: calc(100rpx + constant(safe-area-inset-bottom));
		height: calc(100rpx + env(safe-area-inset-bottom));
		background-color: #fff;
		z-index: 277;
		border-top: 1px solid #f0f0f0;
		display: flex;
		-o-box-align: center;
		align-items: center;
		-o-box-pack: justify;
		justify-content: space-between;
		flex-wrap: nowrap;
		
	} */
</style>